<template>
	<Row style="display: block" class="paper-automatic">
		<!-- <Col span="12" style="width:49%"> -->
		<Col :span="paperType == 'paper_random' ? 24:12">
		<Card id="allQ" dis-hover>
			<div slot="title">
				<p style="display:flex;justify-content: space-between;overflow: visible;">
					<span>所有题目({{autoTotalCount}})</span>
					<span>选题总数:{{autoTotal}} / <span style="color:red">题目上限:100</span></span>
					<Button type="primary" size="small" @click="autoPrevAll()" style="margin-top:-5px;" :disabled="disAutoPrevBtn" v-if="paperType != 'paper_random'">生成试卷题目</Button>
				</p>
			</div>
			<Row class="configClass" style="margin-top:10px;">
				<Col span="4" style="text-align:center;"> CTF题目
				<small style="display:block;line-height:1;color:#FF833A;">（不需要环境）</small>
				<p>({{questionListC.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="questionTypeList"
					v-model="questionTypeCtf"
					:props="props"
					ref="questionTypeCtfRef"
					@change="(val) => getType(val, 6,'questionTypeCtfRef')"
					clearable
					popper-class="high-level"></el-cascader>
					<!-- <Tag color="default" v-for="(item,index) in questionTypeCtfRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.ctfNum" @on-change="changeNumber($event,6)" :formatter="value => value < 0 ? 0 : value"
						:min="0" :max="questionListC.length > 100 ? 100 : questionListC.length" size="small">
					</InputNumber><small v-if="autoPro.ctfNum > questionListC.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.ctfScore" @on-change="autoChangeScore($event,6)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
				</p>
				<p>分值总计：
					<a>{{autoPro.ctfNum * autoPro.ctfScore}}</a>
				</p>
				</Col>
			</Row>
			<Divider dashed />
			<Row class="configClass" style="margin-top:10px;" v-if="isAdvancedExam === 'true'">
				<Col span="4" style="text-align:center;"> CTF题目
				<small style="display:block;line-height:1;color:#FF833A;">（需要环境）</small>
				<p>({{questionListCEnv.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="questionTypeList"
					v-model="questionTypeCtfEnv"
					:props="props"
					ref="questionTypeCtfEnvRef"
					popper-class="high-level"
					@change="(val) => getType(val, 8,'questionTypeCtfEnvRef')"
					clearable></el-cascader>
					<!-- <Tag color="default" v-for="(item,index) in questionTypeCtfEnvRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.ctfNumEnv" @on-change="changeNumber($event,8)" :formatter="value => value < 0 ? 0 : value"
						:min="0" :max="questionListCEnv.length > 100 ? 100 : questionListCEnv.length" size="small">
					</InputNumber><small v-if="autoPro.ctfNumEnv > questionListCEnv.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.ctfScoreEnv" @on-change="autoChangeScore($event,8)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
				</p>
				<p>分值总计：
					<a>{{autoPro.ctfNumEnv * autoPro.ctfScoreEnv}}</a>
				</p>
				</Col>
			</Row>
			<Divider dashed v-if="isAdvancedExam === 'true'"/>
			<Row class="configClass" style="margin-top:10px;" v-show="!isSelfTest">
				<Col span="4" style="text-align:center;"> 问答题
				<p>({{questionListW.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="questionTypeList"
					v-model="questionW"
					:props="props"
					ref="questionWRef"
					@change="(val) => getType(val, 7,'questionWRef')"
					clearable
					popper-class="high-level"></el-cascader>
					<!-- <Tag color="default" v-for="(item,index) in questionWRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.wQuestionNum" @on-change="changeNumber($event,7)" :formatter="value => value < 0 ? 0 : value"
						:min="0" :max="questionListW.length > 100 ? 100 : questionListW.length" size="small">
					</InputNumber><small v-if="autoPro.wQuestionNum > questionListW.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.wQuestionScore" @on-change="autoChangeScore($event,7)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
				</p>
				<p>分值总计：
					<a>{{autoPro.wQuestionNum * autoPro.wQuestionScore}}</a>
				</p>
				</Col>
			</Row>
			<Divider dashed v-show="!isSelfTest"/>
			<Row class="configClass" style="margin-top:10px;">
				<Col span="4" style="text-align:center;"> 单选题
				<p>({{questionListS.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="typeOptions"
					v-model="typeOptionsSingle"
					:props="props"
					ref="typeOptionsSingleRef"
					@change="(val) => getType(val, 1,'typeOptionsSingleRef',autoPro.queryDiffSingle)"
					clearable
					popper-class="high-level"></el-cascader>
					<Select filterable clearable placeholder="请选择难易度" multiple transfer v-model="autoPro.queryDiffSingle" style="width: 100%;margin-top:4px;" @on-change="(val) => queryObjectQuestionList(1, typeOptionsSingle, val)">
						<Option value="simple">简单</Option>
						<Option value="medium">中等</Option>
						<Option value="hard">较难</Option>
					</Select>
					<!-- <Tag color="default" v-for="(item,index) in typeOptionsSingleRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.sQuestionNum" @on-change="changeNumber($event,1)" :formatter="value => value < 0 ? 0 : value" :min="0" :max="questionListS.length > 100 ? 100 : questionListS.length" size="small"></InputNumber>
					<small v-if="autoPro.sQuestionNum > questionListS.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.sQuestionScore" @on-change="autoChangeScore($event,1)" :formatter="value => value > 1000 ? 1000 : (value < 1 ? 1 : value ? value : 1)" :max="1000" :min="1" size="small">
					</InputNumber>
				</p>
				<p>分值总计：
					<a>{{autoPro.sQuestionNum * autoPro.sQuestionScore}}</a>
				</p>
				</Col>
			</Row>
			<Divider dashed />
			<Row class="configClass" style="margin-top:10px;">
				<Col span="4" style="text-align:center;"> 多选题
				<p>({{questionListM.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="typeOptions"
					v-model="typeOptionsMultiple"
					:props="props"
					ref="typeOptionsMultipleRef"
					@change="(val) => getType(val, 2,'typeOptionsMultipleRef',autoPro.queryDiffMultiple)"
					clearable
					popper-class="high-level"></el-cascader>
					<Select filterable clearable placeholder="请选择难易度" multiple transfer v-model="autoPro.queryDiffMultiple" style="width: 100%;margin-top:4px;" @on-change="(val) => queryObjectQuestionList(2, typeOptionsMultiple, val)">
						<Option value="simple">简单</Option>
						<Option value="medium">中等</Option>
						<Option value="hard">较难</Option>
					</Select>
					<!-- <Tag color="default" v-for="(item,index) in typeOptionsMultipleRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.mQuestionNum" @on-change="changeNumber($event,2)" :formatter="value => value < 0 ? 0 : value"
						:min="0" :max="questionListM.length > 100 ? 100 : questionListM.length" size="small">
					</InputNumber><small v-if="autoPro.mQuestionNum > questionListM.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.mQuestionScore" @on-change="autoChangeScore($event,2)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
				</p>
				<p>分值总计：
					<a>{{autoPro.mQuestionNum * autoPro.mQuestionScore}}</a>
				</p>
				</Col>
			</Row>
			<Divider dashed />
			<Row class="configClass" style="margin-top:10px;">
				<Col span="4" style="text-align:center;"> 判断题
				<p>({{questionListP.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="typeOptions"
					v-model="typeOptionsJudge"
					:props="props"
					ref="typeOptionsJudgeRef"
					@change="(val) => getType(val, 3,'typeOptionsJudgeRef',autoPro.queryDiffJudge)"
					clearable
					popper-class="high-level"></el-cascader>
					<Select filterable clearable placeholder="请选择难易度" multiple transfer v-model="autoPro.queryDiffJudge" style="width: 100%;margin-top:4px;" @on-change="(val) => queryObjectQuestionList(3, typeOptionsJudge, val)">
						<Option value="simple">简单</Option>
						<Option value="medium">中等</Option>
						<Option value="hard">较难</Option>
					</Select>
					<!-- <Tag color="default" v-for="(item,index) in typeOptionsJudgeRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.pQuestionNum" @on-change="changeNumber($event,3)" :formatter="value => value < 0 ? 0 : value"
						:min="0" :max="questionListP.length > 100 ? 100 : questionListP.length" size="small">
					</InputNumber><small v-if="autoPro.pQuestionNum > questionListP.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.pQuestionScore" @on-change="autoChangeScore($event,3)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
					</p>
					<p>分值总计：
						<a>{{autoPro.pQuestionNum * autoPro.pQuestionScore}}</a>
					</p>
					</Col>
			</Row>
			<Divider dashed />
			<Row class="configClass" style="margin-top:10px;">
				<Col span="4" style="text-align:center;"> 填空题
				<p>({{questionListT.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<el-cascader style="width: 100%"
					:options="typeOptions"
					v-model="completion"
					:props="props"
					ref="completionRef"
					@change="(val) => getType(val, 4,'completionRef',autoPro.queryDiffCompletion)"
					clearable
					popper-class="high-level"></el-cascader>
					<Select filterable clearable placeholder="请选择难易度" multiple v-model="autoPro.queryDiffCompletion" transfer style="width:100%;margin-top:4px;" @on-change="(val) => queryObjectQuestionList(4,completion, val)">
						<Option value="simple">简单</Option>
						<Option value="medium">中等</Option>
						<Option value="hard">较难</Option>
					</Select>
					<!-- <Tag color="default" v-for="(item,index) in completionRef" :key="index">{{item}}</Tag> -->
				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.tQuestionNum" @on-change="changeNumber($event,4)" :formatter="value => value < 0 ? 0 : value"
						:min="0" :max="questionListT.length > 100 ? 100 : questionListT.length" size="small">
					</InputNumber><small v-if="autoPro.tQuestionNum > questionListT.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.tQuestionScore" @on-change="autoChangeScore($event,4)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
					</p>
					<p>分值总计：
						<a>{{autoPro.tQuestionNum * autoPro.tQuestionScore}}</a>
					</p>
					</Col>
			</Row>
			<!--<Divider dashed />
			<Row class="configClass" style="margin-top:10px;">
				<Col span="4" style="text-align:center;"> 简答题
				<p>({{questionListJ.length}})</p>
				</Col>
				<Col span="11" offset="1">
				<Button shape="circle" :type="autoPro.jQuestionType.includes(item.dictid) ? 'primary' : 'default'" :ghost="autoPro.jQuestionType.includes(item.dictid) ? true : false" v-for="(item,index) in typeCodeObj" :key="index" @click="getType(item,7)" :style="{color:autoPro.jQuestionType.includes(item.dictid) ? 'rgb(56 , 56, 211)':''}" style="padding:2px 4px;margin-right:18px;min-width:60px;">{{item.dictname}}</Button>

				</Col>
				<Col span="7" offset="1">
				<p>选题数量 ：
					<InputNumber v-model="autoPro.jQuestionNum" @on-change="changeNumber($event,5)" :formatter="value => value > 100 ? (questionListJ.length > 100  ? 100 : questionListJ.length) : value.toFixed(0)" :min="0" :max="questionListJ.length > 100 ? 100 : questionListJ.length" size="small">
					</InputNumber><small v-if="autoPro.jQuestionNum > questionListJ.length" style="color: red;display: block">题目数量不足</small></p>
				<p>单题分值 ：
					<InputNumber v-model="autoPro.jQuestionScore" @on-change="autoChangeScore($event,7)" :formatter="value => value > 1000 ? 1000 : value < 1 ? 1 : value ? value : 1" :max="1000" :min="1" size="small">
					</InputNumber>
					<p>分值总计：
						<a>{{autoPro.jQuestionNum * autoPro.jQuestionScore}}</a>
					</p>
					</Col>
			</Row>-->
		</Card>
		</Col>
		<Col span="12" v-if="paperType != 'paper_random'">
		<Card id="selQ" dis-hover>
			<div slot="title">
				<p style="display: flex;justify-content: space-between;">
					<span>已选题目 ({{copySelectQuestionList.length}})</span>
					<span>总分  <span style="color: #2D8CF0;"><b>{{totalScore}}</b></span></span></p>
			</div>
			<div style="padding:10px;word-break:break-all;">
				<Spin size="large" fix v-if="autoPreLoading" style="top:40px"></Spin>
				<QuestionList :data="copySelectQuestionList">
					<template slot="action" slot-scope="{ question,index }">
						<Tooltip content="上移" placement="bottom" @click.native="upQuestion(question,index,'auto')">
							<span class="up"></span>
						</Tooltip>
						<Tooltip content="下移" placement="bottom" @click.native="downQuestion(question,index,'auto')">
							<span class="down"></span>
						</Tooltip>
					</template>
				</QuestionList>
			</div>
			<div class="more" @click="showMore" v-show="selectQuestionList.length > copySelectQuestionList.length">查看更多...</div>
		</Card>
		</Col>
	</Row>
</template>
<script>
	//import Cookies from 'js-cookie';
	import usally from '@/mixin/usally'
	import {
		createTestPaper,
		modifyTestPaper,
		queryTestPaperQuestionList
	} from '@/api/testpaper'
	import {
		queryObjectiveListNoGEQuesPage,
		queryCtfList
	} from '@/api/question'
	import {
		allDirection
	} from '@/api/dict'
	import encryption from '@/libs/encryption.js'
//	import selected from '@/assets/testPaper/selected.png'
//	import up from '@/assets/testPaper/up.png'
//	import up_check from '@/assets/testPaper/up_check.png'
//	import down from '@/assets/testPaper/down.png'
//	import down_check from '@/assets/testPaper/down_check.png'
//	import remove from '@/assets/testPaper/remove.png'
//	import remove_check from '@/assets/testPaper/remove_check.png'
	//import preview from '@/assets/testPaper/remove_check.png'
//	import clear from '@/assets/testPaper/clear.png'
//	import clear_check from '@/assets/testPaper/clear_check.png'
	import {
		debounce
	} from '@/libs/utils'
	import {
		experType
	} from '@/api/dict'
	import QuestionList from '@/components/question-list'
	import common from './mixin.js'
	export default {
		name: 'PaperAutomaticGenerated',
		components: {
			QuestionList
		},
		mixins: [usally,common],
		props:{
			isAdvancedExam: {
				type: String,
				default: 'false'
			},
			isSelfTest: {
				type: Boolean,
				default: false
			},
			'paperVisibility':{
				type:String,
				required:true,
				default:'share'
			},
			'paperCreator':{
				type:String,
				required:true,
				default:''
			},
			'isOwn':{
				type: Boolean,
				default:false
			},
			'selectQuestionList':{
				type: Array,
				default: function () {
			        return []
			    }
			},
			'paperType': {
				type: String,
				default: () => ''
			},
			'opType': {
				type: String,
				default: () => ''
			},
			'paperRandomsDetail': {
				type: Array,
				default: () => []
			}
		},
		data() {
			const validateName = (rule, value, callback) => { //验证只能填入数字
				var reg = new RegExp("^[\u4E00-\u9FA5a-zA-Z0-9_-]*$");
				//验证警戒值
				if(value) {
					if(!reg.test(value)) {
						callback(new Error('请输入中文、数字、字母、下划线、-'));
					} else {
						callback()
					}
				} else {
					callback()
				}
			}
			let September = sessionStorage.getItem('November')
			September = JSON.parse(encryption.SelfUseDecrypt(September))
			return {
				props: {
					multiple: true
				},
				typeOptions: [],
				questionTypeList: [], // 题目类型
				USER_ID: September.userId,
				USER_Name: September.nickname,
				questionListC: [], //不需要环境的ctf
				questionListO: [],
				questionListCEnv: [], //需要环境的ctf
				questionListS: [], //单选题
				questionListM: [], //多选题
				questionListW: [], //问答题
				questionListP: [], //判断题
				questionListT: [], //填空题
				questionListJ: [], //简答题
				autoPro: { //一键生成对象
					pQuestionNum: 1,
					wQuestionNum: this.isSelfTest ? 0 : 1,
					mQuestionNum: 1,
					sQuestionNum: 1,
					tQuestionNum: 1,
					jQuestionNum: 0,
					wQuestionType: [],
					mQuestionType: [],
					sQuestionType: [],
					pQuestionType: [],
					tQuestionType: [],
					jQuestionType: [],
					ctfNum: 1,
					ctfNumEnv: this.isAdvancedExam === 'true' ? 1 : 0,
					ctfType: [],
					ctfTypeEnv: [],
					oprateNum: 1,
					oprateType: '',
					wQuestionScore: 20,
					pQuestionScore: 20,
					mQuestionScore: 20,
					sQuestionScore: 20,
					tQuestionScore: 20,
					jQuestionScore: 20,
					ctfScore: 20,
					ctfScoreMin: 0,
					ctfScoreEnv: 20,
					oprateScore: 20,
					wqustionllist: [],
					squstionllist: [],
					mqustionllist: [],
					pqustionllist: [],
					tqustionllist: [],
					jqustionllist: [],
					ctflist: [],
					ctflistEnv: [],
					// tQuestionName:[],
					// pQuestionName:[],
					// mQuestionName:[],
					// sQuestionName:[],
					// wQuestionName:[],
					// ctfNameEnv:[],
					// ctfName:[],
				},
				typeCodeObj: {},
				tip: {
					ctfNull: false,
					ctfNum: false,
					squestionNull: false,
					squestionNum: false,
					mquestionNull: false,
					mquestionNum: false,
					pquestionNull: false,
					pquestionNum: false,
					wquestionNum: false,
					tquestionNull: false,
					tquestionNum: false,
					jquestionNull: false,
					jquestionNum: false,
				},
				totalScore: 0, //题目总分
				totalCount: 0,
				hideLoadMore: false, //是否隐藏加载更多按钮
				autoPreLoading: false,
				hasIllegalScore: false,
				selectQuestionName: '',
				filterSelectQuestion: function(list) {
					let showList = list; //.filter(ques => ques.description);
					if(this.selectQuestionName) {
						return showList.filter(ques => (ques.description || ques.name).indexOf(this.selectQuestionName) != -1)
					} else {
						return showList
					}
				},
				maxHeight: 'calc(100vh - 336px)',
				saveLoading: false,
				//自动分配显示已选题目
				autoShowSelectQuestionList:[],
				showSelectQuestinPage: 0,
				showSelectQuestinPageSize: 100,
				copySelectQuestionList: [],
				questionTypeCtfRef:[], // ctf 题 级联选择的tag
				questionTypeCtfEnvRef:[], // ctf 题有环境 级联选择的tag
				questionWRef:[], // 问答题 级联选择的tag
				typeOptionsSingleRef:[], // 单选题 级联选择的tag
				typeOptionsMultipleRef:[], // 多选题 级联选择的tag
				typeOptionsJudgeRef:[], // 判断题 级联选择的tag
				completionRef: [], // 填空题 级联选择的tag
				
				// 回显问题
				questionTypeCtf:[], // ctf 题 级联选择的tag
				questionTypeCtfEnv:[], // ctf 题有环境 级联选择的tag
				questionW:[], // 问答题 级联选择的tag
				typeOptionsSingle:[], // 单选题 级联选择的tag
				typeOptionsMultiple:[], // 多选题 级联选择的tag
				typeOptionsJudge:[], // 判断题 级联选择的tag
				completion:[], // 填空题 级联选择的tag
				paramsArr: [],
				letionRef: [],
				num:0,
				autoPrevBtnLoading:false
			}
		},
		computed: {
			autoTotal: function() { //选题总数
				return this.autoPro.sQuestionNum + this.autoPro.mQuestionNum + this.autoPro.pQuestionNum + this.autoPro.wQuestionNum + this.autoPro.tQuestionNum + this.autoPro.ctfNum + this.autoPro.ctfNumEnv //+ this.autoPro.jQuestionNum
			},
			autoTotalCount: function() { //所有的题目总数
				return this.questionListC.length + this.questionListCEnv.length + this.questionListS.length + this.questionListM.length + this.questionListP.length + this.questionListT.length + this.questionListW.length //+ this.questionListJ.length
			},
			disAutoPrevBtn: function() { // this.autoPro.jQuestionNum > this.questionListJ.length 不满足条件禁用生成试卷题目
				return this.autoPrevBtnLoading || this.autoTotal > 100 || this.autoPro.tQuestionNum > this.questionListT.length || this.autoPro.sQuestionNum > this.questionListS.length || this.autoPro.mQuestionNum > this.questionListM.length || this.autoPro.pQuestionNum > this.questionListP.length || this.autoPro.ctfNum > this.questionListC.length || this.autoPro.ctfNumEnv > this.questionListCEnv.length || this.autoPro.wQuestionNum > this.questionListW.length
			},
			countNum () {
				let { ctfNum, ctfScore, wQuestionNum, wQuestionScore, sQuestionNum, sQuestionScore, mQuestionNum, mQuestionScore, pQuestionNum, pQuestionScore, tQuestionNum, tQuestionScore } = this.autoPro
				return { ctfNum, ctfScore, wQuestionNum, wQuestionScore, sQuestionNum, sQuestionScore, mQuestionNum, mQuestionScore, pQuestionNum, pQuestionScore, tQuestionNum, tQuestionScore }
			},

		},
		filters: {
			
		},
		watch: {
			'autoPro.sQuestionNum': function(newValue) {
				this.$set(this.autoPro, 'sQuestionNum', this.getNumber(newValue))
			},
			'autoPro.mQuestionNum': function(newValue) {
				this.$set(this.autoPro, 'mQuestionNum', this.getNumber(newValue))
			},
			'autoPro.pQuestionNum': function(newValue) {
				this.$set(this.autoPro, 'pQuestionNum', this.getNumber(newValue))
			},
			'autoPro.tQuestionNum': function(newValue) {
				this.$set(this.autoPro, 'tQuestionNum', this.getNumber(newValue))
			},
			'autoPro.ctfNum': function(newValue) {
				this.$set(this.autoPro, 'ctfNum', this.getNumber(newValue))
			},
			'autoPro.ctfNumEnv': function(newValue) {
				this.$set(this.autoPro, 'ctfNumEnv', this.getNumber(newValue))
			},
			'autoPro.wQuestionNum': function(newValue) {
				this.$set(this.autoPro, 'wQuestionNum', this.getNumber(newValue))
			},
			// 存在提交报告的题目时，需要提示父组件禁止修改“自测”属性，反之通知允许修改
			copySelectQuestionList(list) {
				this.$emit('change-type', list.some(item => item.flagType === '3'))
				this.$emit('has-evn', list.some(item => item.needEnv === 1))
			},
			'selectQuestionList':function(val) {
				this.getTotalScore();
			},
			'paperVisibility': function(val) {
				if(val === 'share' && !this.$route.id) {
					this.copySelectQuestionList.forEach((question, index) => {
						if(question.visibility == 'private') {
							this.removeQuestion(question, index)
						}
					})
				}
			},
			isSelfTest(val) {
				this.queryCtfQuestionList(6)
				if (this.isAdvancedExam === 'true') { // 进阶试卷需要查询需要环境的CTF题目
					this.queryCtfQuestionList(8)
				}
				if (!val) { // 自测试卷不需要查询问答题
					this.queryCtfQuestionList(7)
				}
				this.autoPro = { // 还原数据
					pQuestionNum: 1,
					mQuestionNum: 1,
					sQuestionNum: 1,
					tQuestionNum: 1,
					wQuestionNum: val ? 0 : 1,
					jQuestionNum: 0,
					wQuestionType: [],
					mQuestionType: [],
					sQuestionType: [],
					pQuestionType: [],
					tQuestionType: [],
					jQuestionType: [],
					ctfNum: 1,
					ctfNumEnv: this.isAdvancedExam === 'true' ? 1 : 0,
					ctfType: [],
					ctfTypeEnv: [],
					oprateNum: 1,
					oprateType: '',
					pQuestionScore: 20,
					wQuestionScore: 20,
					mQuestionScore: 20,
					sQuestionScore: 20,
					tQuestionScore: 20,
					jQuestionScore: 20,
					ctfScore: 20,
					ctfScoreMin: 0,
					ctfScoreEnv: 20,
					oprateScore: 20,
					wqustionllist: [],
					squstionllist: [],
					mqustionllist: [],
					pqustionllist: [],
					tqustionllist: [],
					jqustionllist: [],
					ctflist: [],
					ctflistEnv: [],
				}
				this.copySelectQuestionList = []
			},
			isAdvancedExam(val) {
				this.queryCtfQuestionList(6)
				if (val === 'true') { // 进阶试卷需要查询需要环境的CTF题目
					this.queryCtfQuestionList(8)
				}
				if (!this.isSelfTest) { // 自测试卷不需要查询问答题
					this.queryCtfQuestionList(7)
				}
				this.autoPro = { // 还原数据
					pQuestionNum: 1,
					mQuestionNum: 1,
					sQuestionNum: 1,
					tQuestionNum: 1,
					wQuestionNum: this.isSelfTest ? 0 : 1,
					jQuestionNum: 0,
					wQuestionType: [],
					mQuestionType: [],
					sQuestionType: [],
					pQuestionType: [],
					tQuestionType: [],
					jQuestionType: [],
					ctfNum: 1,
					ctfNumEnv: val === 'true' ? 1 : 0,
					ctfType: [],
					ctfTypeEnv: [],
					oprateNum: 1,
					oprateType: '',
					pQuestionScore: 20,
					wQuestionScore: 20,
					mQuestionScore: 20,
					sQuestionScore: 20,
					tQuestionScore: 20,
					jQuestionScore: 20,
					ctfScore: 20,
					ctfScoreMin: 0,
					ctfScoreEnv: 20,
					oprateScore: 20,
					wqustionllist: [],
					squstionllist: [],
					mqustionllist: [],
					pqustionllist: [],
					tqustionllist: [],
					jqustionllist: [],
					ctflist: [],
					ctflistEnv: [],
				}
				this.copySelectQuestionList = []
			},
			countNum: {
				handler (val) {
					// this.getParams()
					// this.$emit('changeArr',this.paramsArr)
				},
				deep: true,
			},
			questionTypeList: {
				handler (val) {
					// let arr= []
					// val.forEach(item => {
					// 	this.questionTypeCtfRef.forEach(item2 => {
					// 		if (item2 == item.label) {
					// 			 arr.push([item.value])
					// 		}
					// 	})
					// })
					// this.questionTypeCtf = arr
					// console.log('===', this.questionTypeCtfRef);
					this.questionTypeCtf = this.resultArr(val,'questionTypeCtfRef')
					this.questionW = this.resultArr(val,'questionWRef')
					this.questionTypeCtfEnv = this.resultArr(val,'questionTypeCtfEnvRef')
					if(this.opType == 'modify'){
            		this.getType(this.questionTypeCtf,6,'questionTypeCtfRef')
					this.getType(this.questionW,7,'questionWRef')
					if (this.isAdvancedExam === 'true') { // ctf 需要环境
						this.getType(this.questionTypeCtfEnv,8,'questionTypeCtfEnvRef')
					}
				}
			},
				deep:true
			},
			typeOptions:{
				handler(val){
					this.typeOptionsSingle = this.childrenArr(val,'typeOptionsSingleRef')
					this.typeOptionsMultiple = this.childrenArr(val,'typeOptionsMultipleRef')
					this.typeOptionsJudge = this.childrenArr(val,'typeOptionsJudgeRef')
					this.completion = this.childrenArr(val, 'completionRef')
					if(this.opType == 'modify'){
						this.getType(this.typeOptionsSingle,1,'typeOptionsSingleRef')
						this.getType(this.typeOptionsMultiple,2,'typeOptionsMultipleRef')
						this.getType(this.typeOptionsJudge,3,'typeOptionsJudgeRef')
						this.getType(this.completion,4,'completionRef')
					}
				},
				deep:true
			},
		},
		mounted() {
			this.getQuestionType()
			this.getAllPoint(); //查询知识点
			if (this.opType !== 'modify') {
				//一键生成初始数据 获取所有的 单选，多选，判断，ctf题
				this.queryObjectQuestionList(1); //单选
				this.queryObjectQuestionList(2); //多选
				this.queryObjectQuestionList(3); //判断
				this.queryObjectQuestionList(4); //填空题
				this.queryCtfQuestionList(6);
				this.queryCtfQuestionList(7); //ctf题--不需要环境
				if (this.isAdvancedExam === 'true') {
					this.queryCtfQuestionList(8)
				}
			}
			this.getTotalScore();
			//this.queryObjectQuestionList(5); //简答题
			this.copySelectQuestionList = [...this.selectQuestionList];
			this.paperRandomsDetailNumber()
			this.getParams()
		},
	methods: {
		// 遍历回显只有一级问题
			resultArr(val,name){
				let arr =[]
				val.forEach(item => {
						this[name].forEach(item2 => {
							if (item2 == item.label) {
								 arr.push([item.value])
							}
						})
					})
					return arr;
			},
			// 遍历回显有二级问题
		childrenArr (val, name) {
			let arr = []
			val.forEach(item => {
				item.children.forEach(item2 => {
					this[name].forEach(item3 => {
						let code  = item3.split(',')
						if (code[0] == item.value && code[1] == item2.value) {
							arr.push([item.value, item2.value])
						}
					})
				})
			})
			return arr
		},
			// 控制题目输入，不合法的输入全部改为0
			getNumber(val) {
				let num = val
				if (!num) {
					return 0
				} else {
					let intNum = Math.floor(val)
					return intNum >= 0 ? intNum : 0
				}
			},
			// 获取题目类型
			getQuestionType() {
				experType('questionType').then(({
					code,
					message,
					attribute = []
				}) => {
					if(code !== 1) {
						this.$Message.warning(message)
					} else {
						this.questionTypeList = ((attribute.attribute[0] || {}).dictEntryList || []).map(item => {
							return {
								value: unescape(item.dictname),
								label: unescape(item.dictname)
							}
						})
					}
				}).catch(() => {
					this.$Message.error('获取题目类型异常')
				})
			},
			getAllPoint() { //获取所有方向
				experType().then(data => {
					if(data.code === 1) {
						let retList = []
						let list = data.attribute.attribute[0].dictEntryList
						// 遍历两次是防止父方向还不存在，就已经添加子方向了，损失了性能，确保数据填充的正确性
						list.forEach(item => { // 配置父方向
							if (!item.parentid) {
								retList.push({
									value: item.dictid,
									label: item.dictname,
									children: []
								})
							}
						})
						list.forEach(item => { // 配置子方向
							if (item.parentid) {
								let index = retList.findIndex(subItem => subItem.value === item.parentid)
								retList[index].children.push({
									value: item.dictid,
									label: item.dictname
								})
							}
						})
						this.typeOptions = retList
					}
				})
			},
			queryObjectiveAnswerList(item) { //整理答案
				let answ = this.sortQuestionAnswer(item.answers)
				this.$set(item, 'answers', answ);
			},
			//获取总分值
			getTotalScore() {
				this.totalScore = 0;
				let scoreList = this.copySelectQuestionList.map(question => question.score || 0)
				this.totalScore = scoreList.reduce((count, v) => count + v, 0)
			},
			queryQuestionInfo(question) { //查询题目详情
				let score = JSON.parse(JSON.stringify(question.score));
				question.score = score;
				question.modeCode = this.transferPapertypeToQuestionModeCode(question.questionType);
				// if(question.modeCode === '3') { //如果是判断题
				// 	this.$set(question, 'answers', this.generateTorFQuestionsAnswer(question));
				// }
			},
			clearSelectQuestion() {
				this.copySelectQuestionList = [];
				this.totalScore = 0;
			},
			upQuestion(ques, index, type) {
				if(index == 0) {
					return;
				}
				let arr = this.copySelectQuestionList; //this.copySelectQuestionList;
				arr.splice(index, 1, ...arr.splice(index - 1, 1, arr[index]))
				let autArr = this.autoShowSelectQuestionList;
				autArr.splice(index, 1, ...autArr.splice(index - 1, 1, autArr[index]))
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore)
			},
			downQuestion(ques, index, type) {
				if(index == this.autoShowSelectQuestionList.length - 1) {
					return;
				}
				let arr = this.copySelectQuestionList;
				arr.splice(index + 1, 1, ...arr.splice(index, 1, arr[index + 1]))
				let autoArr = this.autoShowSelectQuestionList; //this.selectQuestionList;
				autoArr.splice(index + 1, 1, ...autoArr.splice(index, 1, autoArr[index + 1]))
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore)
			},
			autoChangeScore: debounce(function(qscore, type) { //一键生成改变分数
				this.hasIllegalScore = false;
				if(this.autoPro.ctfNum > 0 && this.autoPro.ctfScore == 0) {
					this.hasIllegalScore = true;
				}
				if(this.autoPro.ctfNumEnv > 0 && this.autoPro.ctfScoreEnv == 0) {
					this.hasIllegalScore = true;
				}
				if(this.autoPro.sQuestionNum > 0 && this.autoPro.sQuestionScore == 0) {
					this.hasIllegalScore = true;
				}
				if(this.autoPro.mQuestionNum > 0 && this.autoPro.mQuestionScore == 0) {
					this.hasIllegalScore = true;
				}
				if(this.autoPro.pQuestionNum > 0 && this.autoPro.pQuestionScore == 0) {
					this.hasIllegalScore = true;
				}
				if(this.autoPro.wQuestionNum > 0 && this.autoPro.wQuestionScore == 0) {
					this.hasIllegalScore = true;
				}
				if(this.autoPro.tQuestionNum > 0 && this.autoPro.tQuestionScore == 0) {
					this.hasIllegalScore = true;
				}
				let score = qscore ? (qscore > 1000 ? 1000 : qscore < 1 ? 1 : qscore) : 1;
				score = Math.floor(score)
				if(type == 6) {
					this.$set(this.autoPro, 'ctfScore', score)
					this.autoPro.ctflist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.ctfScore);
					})
				} else if(type == 8) {
					this.$set(this.autoPro, 'ctfScoreEnv', score)
					this.autoPro.ctflistEnv.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.ctfScoreEnv);
					})
				}else if(type == 1) {
					this.$set(this.autoPro, 'sQuestionScore', score)
					this.autoPro.squstionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.sQuestionScore);
					})
				} else if(type == 2) {
					this.$set(this.autoPro, 'mQuestionScore', score)
					this.autoPro.mqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.mQuestionScore);
					})
				} else if(type == 3) {
					this.$set(this.autoPro, 'pQuestionScore', score)
					this.autoPro.pqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.pQuestionScore);
					})
				} else if(type == 4) {
					this.$set(this.autoPro, 'tQuestionScore', score)
					this.autoPro.tqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.tQuestionScore);
					})
				} else if(type == 7) {
					this.$set(this.autoPro, 'wQuestionScore', score)
					this.autoPro.wqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.wQuestionScore);
					})
				}
				this.getTotalScore();
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore)
			}, 500),
			//随机数函数
			ramdomArr(range, num) {
				let arr = []
				if(range < num) {
					for(let j = 0; j < range; j++) {
						arr.push(j)
					}
				} else {
					for(let i = 0; i < num; i++) {
						let num = parseInt(Math.random() * range);
						while(arr.includes(num)) {
							num = parseInt(Math.random() * range);
						}
						arr.push(num);
					}
				}
				return arr;
			},
			changeNumber: debounce(function(qnum, type) { //修改题目数量的回调
			if(qnum==0){
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore,{
					sQuestionNum:this.autoPro.sQuestionNum,
					mQuestionNum:this.autoPro.mQuestionNum,
					pQuestionNum:this.autoPro.pQuestionNum,
					tQuestionNum:this.autoPro.tQuestionNum,
					wQuestionNum:this.autoPro.wQuestionNum,
					ctfNum: this.autoPro.ctfNum 
				})
			}
				if (this.autoPro.sQuestionNum > this.questionListS.length 
					|| this.autoPro.mQuestionNum > this.questionListM.length
					|| this.autoPro.pQuestionNum > this.questionListP.length
					|| this.autoPro.tQuestionNum > this.questionListT.length
					|| this.autoPro.jQuestionNum > this.questionListJ.length
					|| this.autoPro.ctfNum > this.questionListC.length
					|| this.autoPro.wQuestionNum > this.questionListW.length) {
						// this.autoPro.ctfNum = this.questionListC.length
						// this.autoPro.wQuestionNum = this.questionListW.length
						// this.autoPro.sQuestionNum = this.questionListS.length 
						// this.autoPro.mQuestionNum = this.questionListM.length
						// this.autoPro.pQuestionNum = this.questionListP.length
						// this.autoPro.tQuestionNum = this.questionListT.length
						// 判断输入数量后，默认为加载的数量值
						if (this.questionTypeCtf.length > 0 && this.autoPro.ctfNum > this.questionListC.length ) {
							this.autoPro.ctfNum = this.questionListC.length
						}else if(this.questionTypeCtfEnv.length > 0 && this.autoPro.ctfNumEnv > this.questionListCEnv.length){
							this.autoPro.ctfNumEnv = this.questionListCEnv.length
						}else if(this.questionW.length > 0 && this.autoPro.wQuestionNum > this.questionListW.length){
							this.autoPro.wQuestionNum = this.questionListW.length
						}else if(this.typeOptionsSingle.length>0 && this.autoPro.sQuestionNum > this.questionListS.length ){
							this.autoPro.sQuestionNum = this.questionListS.length 
						}else if(this.typeOptionsMultiple.length>0 && this.autoPro.mQuestionNum > this.questionListM.length){
							 this.autoPro.mQuestionNum = this.questionListM.length
						}else if(this.typeOptionsJudge.length>0 && this.autoPro.pQuestionNum > this.questionListP.length){
							this.autoPro.pQuestionNum = this.questionListP.length
						}else if(this.completion.length>0 && this.autoPro.tQuestionNum > this.questionListT.length){
							 this.autoPro.tQuestionNum = this.questionListT.length
						}
					this.$Message.warning('试题数量不足,输入数量默认设置为允许设置的最大值')
					this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore,{
					sQuestionNum:this.autoPro.sQuestionNum,
					mQuestionNum:this.autoPro.mQuestionNum,
					pQuestionNum:this.autoPro.pQuestionNum,
					tQuestionNum:this.autoPro.tQuestionNum,
					wQuestionNum:this.autoPro.wQuestionNum,
					ctfNum: this.autoPro.ctfNum 
				})
					return
				}
				let num = qnum ? qnum < 0 ? 0 : (parseInt(qnum.toFixed(0)) > 100 ? 100 : parseInt(qnum.toFixed(0))) : 0;
				if(type == 6) {
					this.autoPro.ctfNum = num > this.questionListC.length ? this.questionListC.length : num;
				} else if(type == 1) {
					this.autoPro.sQuestionNum = num > this.questionListS.length ? this.questionListS.length : num;
				} else if(type == 2) {
					this.autoPro.mQuestionNum = num > this.questionListM.length ? this.questionListM.length : num;
				} else if(type == 3) {
					this.autoPro.pQuestionNum = num > this.questionListP.length ? this.questionListP.length : num;
				} else if(type == 4) {
					this.autoPro.tQuestionNum = num > this.questionListT.length ? this.questionListT.length : num;
				} else if(type == 5) {
					this.autoPro.jQuestionNum = num > this.questionListJ.length ? this.questionListJ.length : num;
				} else if (type == 7) {
					this.autoPro.wQuestionNum = num > this.questionListW.length ? this.questionListW.length : num;
				} else if(type == 8) {
					this.autoPro.ctfNumEnv = num > this.questionListCEnv.length ? this.questionListCEnv.length : num;
				}
				if(this.autoTotal > 100) {
					this.$Message.warning('已达题目添加上限100,请修改选题数量');
					return;
				}
				if((type == 6 && this.autoPro.ctfNum == this.autoPro.ctflist.length) ||
					(type == 8 && this.autoPro.ctfNumEnv == this.autoPro.ctflistEnv.length) ||
					(type == 7 && this.autoPro.wQuestionNum == this.autoPro.wqustionllist.length) ||
					(type == 1 && this.autoPro.sQuestionNum == this.autoPro.squstionllist.length) ||
					(type == 2 && this.autoPro.mQuestionNum == this.autoPro.mqustionllist.length) ||
					(type == 3 && this.autoPro.pQuestionNum == this.autoPro.pqustionllist.length) ||
					(type == 4 && this.autoPro.tQuestionNum == this.autoPro.tqustionllist.length) ||
					(type == 5 && this.autoPro.jQuestionNum == this.autoPro.jqustionllist.length)) {
					return
				}
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore,{
					sQuestionNum:this.autoPro.sQuestionNum,
					mQuestionNum:this.autoPro.mQuestionNum,
					pQuestionNum:this.autoPro.pQuestionNum,
					tQuestionNum:this.autoPro.tQuestionNum,
					wQuestionNum:this.autoPro.wQuestionNum,
					ctfNum: this.autoPro.ctfNum 
				})
				//this.autoPreview(type);
			}, 500),
			autoPrevAll() {
				// if((this.autoPro.ctfNum == this.autoPro.ctflist.length) &&
				// 	(this.autoPro.ctfNumEnv == this.autoPro.ctflistEnv.length) &&
				// 	(this.autoPro.sQuestionNum == this.autoPro.squstionllist.length) &&
				// 	(this.autoPro.mQuestionNum == this.autoPro.mqustionllist.length) &&
				// 	(this.autoPro.pQuestionNum == this.autoPro.pqustionllist.length) &&
				// 	(this.autoPro.tQuestionNum == this.autoPro.tqustionllist.length) &&
				// 	(this.autoPro.wQuestionNum == this.autoPro.wqustionllist.length) &&
				// 	(this.autoPro.jQuestionNum == this.autoPro.jqustionllist.length)) {
				// 	return
				// }
				this.showSelectQuestinPage = 0;
				this.copySelectQuestionList = [];
				this.autoPreview(1);
				this.autoPreview(2);
				this.autoPreview(3);
				this.autoPreview(4);
				this.autoPreview(5);
				this.autoPreview(6);
				if (!this.isSelfTest) { // 自测试卷不需要生成问答题
					this.autoPreview(7);
				}
				if (this.isAdvancedExam === 'true') {
					this.autoPreview(8);
				}
				//获取当前显示已选题目
				this.showMore();
			},
			autoPreview(type) { //自动生成题目
				//(paperTestformValidate.isPublic == 1 || !isOwn) && question.visibility == 'private'
				// if((type == 6 && this.autoPro.ctfNum == this.autoPro.ctflist.length) ||
				// 	(type == 8 && this.autoPro.ctfNumEnv == this.autoPro.ctflistEnv.length) ||
				// 	(type == 7 && this.autoPro.wQuestionNum == this.autoPro.wqustionllist.length) ||
				// 	(type == 1 && this.autoPro.sQuestionNum == this.autoPro.squstionllist.length) ||
				// 	(type == 2 && this.autoPro.mQuestionNum == this.autoPro.mqustionllist.length) ||
				// 	(type == 3 && this.autoPro.pQuestionNum == this.autoPro.pqustionllist.length) ||
				// 	(type == 4 && this.autoPro.tQuestionNum == this.autoPro.tqustionllist.length) ||
				// 	(type == 5 && this.autoPro.jQuestionNum == this.autoPro.jqustionllist.length)) {
				// 	return
				// }
				if(type == 6 || !type) {
					if(this.questionListC.length > this.autoPro.ctfNum) {
						this.autoPro.ctflist = this.ramdomArr(this.questionListC.length, this.autoPro.ctfNum).map(index => {
							return this.questionListC.slice(index, index + 1)[0]
						});
					} else if(this.questionListC.length <= this.autoPro.ctfNum) {
						this.autoPro.ctflist = this.questionListC;
					}
					this.autoPro.ctflist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.ctfScore);
					})
				}
				if(type == 8 || !type) {
					if(this.questionListCEnv.length > this.autoPro.ctfNumEnv) {
						this.autoPro.ctflistEnv = this.ramdomArr(this.questionListCEnv.length, this.autoPro.ctfNumEnv).map(index => {
							return this.questionListCEnv.slice(index, index + 1)[0]
						});
					} else if(this.questionListCEnv.length <= this.autoPro.ctfNumEnv) {
						this.autoPro.ctflistEnv = this.questionListCEnv;
					}
					this.autoPro.ctflistEnv.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.ctfScoreEnv);
					})
				}
				if(type == 1 || !type) {
					if(this.questionListS.length > this.autoPro.sQuestionNum) {
						this.autoPro.squstionllist = this.ramdomArr(this.questionListS.length, this.autoPro.sQuestionNum).map(index => {
							return this.questionListS.slice(index, index + 1)[0]
						});
					} else if(this.questionListS.length <= this.autoPro.sQuestionNum) {
						this.autoPro.squstionllist = this.questionListS;
					}
					this.autoPro.squstionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.sQuestionScore);
					})
				}
				if(type == 7 || !type) {
					if(this.questionListW.length > this.autoPro.wQuestionNum) {
						this.autoPro.wqustionllist = this.ramdomArr(this.questionListW.length, this.autoPro.wQuestionNum).map(index => {
							return this.questionListW.slice(index, index + 1)[0]
						});
					} else if(this.questionListW.length <= this.autoPro.wQuestionNum) {
						this.autoPro.wqustionllist = this.questionListW;
					}
					this.autoPro.wqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.wQuestionScore);
					})
				}
				if(type == 2 || !type) {
					if(this.questionListM.length > this.autoPro.mQuestionNum) {
						this.autoPro.mqustionllist = this.ramdomArr(this.questionListM.length, this.autoPro.mQuestionNum).map(index => {
							return this.questionListM.slice(index, index + 1)[0]
						});
					} else if(this.questionListM.length <= this.autoPro.mQuestionNum) {
						this.autoPro.mqustionllist = this.questionListM;
					}
					this.autoPro.mqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.mQuestionScore);
					})
				}
				if(type == 3 || !type) {
					if(this.questionListP.length > this.autoPro.pQuestionNum) {
						this.autoPro.pqustionllist = this.ramdomArr(this.questionListP.length, this.autoPro.pQuestionNum).map(index => {
							return this.questionListP.slice(index, index + 1)[0]
						});
					} else if(this.questionListP.length <= this.autoPro.pQuestionNum) {
						this.autoPro.pqustionllist = this.questionListP;
					}
					this.autoPro.pqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.pQuestionScore);
					})
				}
				if(type == 4 || !type) {
					if(this.questionListT.length > this.autoPro.tQuestionNum) {
						this.autoPro.tqustionllist = this.ramdomArr(this.questionListT.length, this.autoPro.tQuestionNum).map(index => {
							return this.questionListT.slice(index, index + 1)[0]
						});
					} else if(this.questionListT.length <= this.autoPro.tQuestionNum) {
						this.autoPro.tqustionllist = this.questionListT;
					}
					this.autoPro.tqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.tQuestionScore);
					})
				}
				if(type == 5 || !type) {
					if(this.questionListJ.length > this.autoPro.jQuestionNum) {
						this.autoPro.jqustionllist = this.ramdomArr(this.questionListJ.length, this.autoPro.jQuestionNum).map(index => {
							return this.questionListJ.slice(index, index + 1)[0]
						});
					} else if(this.questionListJ.length <= this.autoPro.jQuestionNum) {
						this.autoPro.jqustionllist = this.questionListJ;
					}
					this.autoPro.jqustionllist.forEach(ques => {
						this.$set(ques, 'score', this.autoPro.jQuestionScore);
					})
				}
				this.copySelectQuestionList = [...this.autoPro.ctflist,  ...this.autoPro.ctflistEnv, ...this.autoPro.squstionllist, ...this.autoPro.mqustionllist, ...this.autoPro.pqustionllist, ...this.autoPro.tqustionllist, ...this.autoPro.jqustionllist, ...this.autoPro.wqustionllist];
				this.getTotalScore();
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore)
			},
			showMore() { //点击查看更多的按钮回调
				this.showSelectQuestinPage++;
				let data = this.copySelectQuestionList.slice((this.showSelectQuestinPage - 1) * this.showSelectQuestinPageSize, this.showSelectQuestinPage * this.showSelectQuestinPageSize);
				this.autoShowSelectQuestionList = this.autoShowSelectQuestionList.concat(data);
				let objectList = data.filter(ques => ['1','2','3','4','5'].includes(ques.modeCode));
				objectList.forEach(ques => {
					this.queryObjectiveAnswerList(ques);
				})
			},
			queryCtfQuestionList(type, list) { //查询ctf题列表-不分页--不需要环境
				let ctfquery = {
					pageIndex: 1,
					pageSize: 999,
				};
				let obj = {}
				if (type === 6) {
					obj = {
						needEnv: 'false',
						otherFlagType: '1,2,3',
					};
				} else if (type === 8) {
					obj = {
						needEnv: 'true',
						flagType: '0',
					}
				} else {
					obj = {
						matchMode: 3,
					}
				}
				if (Array.isArray(list) && list.length) {
					obj.category = list.join(',')
				}
				let _this = this;
				queryCtfList(obj, ctfquery, true).then(data => {
					if(data.code == 1) {
						let quesList = data.data.items || data.data;
						let availableQuesList = [];
						quesList.forEach(item => {
							item._disabled = this.getDisabledStatus(item);
							if(!item.name) {
								item.name = item.description;
							}
							item.modeCode = '6';
							if(!item._disabled) {
								availableQuesList.push(item);
							}
							if (!item.flagTxt) { // flagTxt字段没有值，需要重新设值
								let list = (item.answers && item.answers.map(item => item.flag)) || []
								item.flagTxt = list.length ? list.join(', ') : ''
							}
						})
						if (type === 6) {
							_this.questionListC = availableQuesList;
							_this.autoPro.ctfNum = Math.min(_this.questionListC.length, _this.autoPro.ctfNum);
						} else if (type === 8) {
							_this.questionListCEnv = availableQuesList;
							_this.autoPro.ctfNumEnv = Math.min(_this.questionListCEnv.length, _this.autoPro.ctfNumEnv);
						} else {
							_this.questionListW = availableQuesList;
							_this.autoPro.wQuestionNum = Math.min(_this.questionListW.length, _this.autoPro.wQuestionNum);
						}
						if(this.testPaperType == 2) {
							//_this.autoPreview(4)
						}
					} else {
						_this.$Message.warning(data.message);
					}
				}).catch(error => {
				})
			},
			getCheckedNode (name) {
				console.log('🚀 getCheckedNode ~ arr', this[name])
				this.getParams()
			},
		getType (list, type, refName, diff) {
				// console.log('🚀 ~ file: paper-automatic-generated.vue:1224 ~ getType ~ list', list)
				this[refName] = this.$refs[refName].getCheckedNodes().map(item => item.label)
				// console.log('🚀 ~ file: paper-automatic-generated.vue:1178 ~ getType ~ this[refName]', this[refName])
				// this.changeName(list, type, refName)
				if(type == 6 || type == 7 || type == 8) {
					this.queryCtfQuestionList(type, list);
				} else {
					this.queryObjectQuestionList(type, list, diff);
				}
				// this.getCheckedNode(refName)
			},
			changeName (list, type, refName) {
				if (type == 6) {
					this.autoPro.ctfName = list
				}
				if (type == 8) {
					this.autoPro.ctfNameEnv = list
				}
				if (type == 7) {
					this.autoPro.wQuestionName = list
				}
				if (type == 1) {
					this.autoPro.sQuestionName = list
				}
				if (type == 2) {
					this.autoPro.mQuestionName = list
				}
				if (type == 3) {
					this.autoPro.pQuestionName = list
				}
				if (type == 4) {
					this.autoPro.tQuestionName = list
				}
				console.log('===this.tQuestionName',this.autoPro.ctfName);
			},
		queryObjectQuestionList (val, list, diff) { //查询客观题列表-不分页
			this.autoPrevBtnLoading = true;
			this.num++
				let num = this.num
				let _this = this;
				if(val == 1 || val == 2 || val == 3 || val == 4 || val == 5) {
					let obj = {
						pageIndex: 1,
						pageSize: 9999,
						modeCode: val
					}
					if (Array.isArray(list) && list.length) {
						let typeCodes = []
						list.forEach(item => {
							typeCodes.push(item[item.length - 1])
						})
						obj.typeCode = typeCodes.join(',')
					}
					obj.difficulty = diff ? diff.join(',') : '';
					queryObjectiveListNoGEQuesPage(obj).then(data => {
						if(data.code === 1) {
							let quesList = data.data.items || data.data;
							let availableQuesList = [];
							quesList.forEach(item => {
								item._disabled = this.getDisabledStatus(item);
								if(!item.name) {
									item.name = item.description;
								}
								if(item.modeCode == 4) {
									item.description = item.explanation;
								}
								if(!item._disabled) {
									availableQuesList.push(item);
								}
							})
							// if (num == this.num) {
								switch(val) {
								case 1:
									_this.questionListS = availableQuesList;
									_this.autoPro.sQuestionNum = Math.min(_this.questionListS.length, _this.autoPro.sQuestionNum);
									break;
								case 2:
									_this.questionListM = availableQuesList;
									_this.autoPro.mQuestionNum = Math.min(_this.questionListM.length, _this.autoPro.mQuestionNum);
									break;
								case 3:
									_this.questionListP = availableQuesList;
									_this.autoPro.pQuestionNum = Math.min(_this.questionListP.length, _this.autoPro.pQuestionNum);
									break;
								case 4:
									_this.questionListT = availableQuesList;
									_this.autoPro.tQuestionNum = Math.min(_this.questionListT.length, _this.autoPro.tQuestionNum);
									break;
								case 5:
									_this.questionListJ = availableQuesList;
									_this.autoPro.jQuestionNum = Math.min(_this.questionListJ.length, _this.autoPro.jQuestionNum);
									break;
								default:
									break;
							}
							// }
							
							if(this.testPaperType == 2) {
								//_this.autoPreview(val)
							}
							this.autoPrevBtnLoading = false;
						} else {
							this.autoPrevBtnLoading = false;
							this.$Message.warning(data.message);
						}
						//          }
					}).catch(error => {
						this.autoPrevBtnLoading = false;
						this.$Message.error(error.error);
					})
				}
			},
			getDisabledStatus(question) {
				let isNotCommonCreator = this.paperCreator === question.creator;
				return(this.paperVisibility == 'share' || (!this.isOwn && isNotCommonCreator)) && question.visibility == 'private'
			},
			// 处理数据生成参数
		getParams () {
			let obj = {}
			let arr = []
			let score = []
			if (this.autoPro.ctfNum > 0) {
				let questionTypeCtf = this.getArr(this.questionTypeCtf)
				obj = this.getObj(questionTypeCtf, this.autoPro.ctfNum, this.autoPro.ctfScore, 'ctf_no_env')
				arr.push(obj)
				score.push(this.autoPro.ctfNum * this.autoPro.ctfScore)
			}
			if (this.autoPro.ctfNumEnv > 0) {
				let questionTypeCtfEnv = this.getArr(this.questionTypeCtfEnv)
				obj = this.getObj(questionTypeCtfEnv, this.autoPro.ctfNumEnv, this.autoPro.ctfScoreEnv, 'ctf_env')
				arr.push(obj)
				score.push(this.autoPro.ctfNumEnv * this.autoPro.ctfScoreEnv)
			}
			if (this.autoPro.wQuestionNum > 0) {
				let questionW = this.getArr(this.questionW)
				obj = this.getObj(questionW, this.autoPro.wQuestionNum, this.autoPro.wQuestionScore, 'qa')
				arr.push(obj)
				score.push(this.autoPro.wQuestionNum * this.autoPro.wQuestionScore)
			}
			if (this.autoPro.sQuestionNum > 0) {
				let typeOptionsSingle = this.childrenArr12('typeOptionsSingle')
				obj = this.getObj(typeOptionsSingle, this.autoPro.sQuestionNum, this.autoPro.sQuestionScore, 'single_choice')
				arr.push(obj)
				score.push(this.autoPro.sQuestionNum * this.autoPro.sQuestionScore)
			}
			if (this.autoPro.mQuestionNum > 0) {
				let typeOptionsMultiple = this.childrenArr12('typeOptionsMultiple')
				obj = this.getObj(typeOptionsMultiple, this.autoPro.mQuestionNum, this.autoPro.mQuestionScore, 'multiple_choice')
				arr.push(obj)
				score.push(this.autoPro.mQuestionNum * this.autoPro.mQuestionScore)
			}
			if (this.autoPro.pQuestionNum > 0) {
				let typeOptionsJudge = this.childrenArr12('typeOptionsJudge')
				obj = this.getObj(typeOptionsJudge, this.autoPro.pQuestionNum, this.autoPro.pQuestionScore, 'judge')
				arr.push(obj)
				score.push(this.autoPro.pQuestionNum * this.autoPro.pQuestionScore)
			}
			if (this.autoPro.tQuestionNum > 0) {
				let completion = this.childrenArr12('completion')
				obj = this.getObj(completion, this.autoPro.tQuestionNum, this.autoPro.tQuestionScore, 'blank_filling') // 填空题
				arr.push(obj)
				score.push(this.autoPro.tQuestionNum * this.autoPro.tQuestionScore)
			}
			this.paramsArr = JSON.parse(JSON.stringify(arr));
			// console.log(' getParams ~ this.paramsArr', this.paramsArr)
			this.getTotalScoreNew(score)
			this.$emit('changeArr', this.paramsArr)
			this.$emit('on-change', this.copySelectQuestionList, this.totalScore, this.autoTotal, this.hasIllegalScore,{
					sQuestionNum:this.autoPro.sQuestionNum,
					mQuestionNum:this.autoPro.mQuestionNum,
					pQuestionNum:this.autoPro.pQuestionNum,
					tQuestionNum:this.autoPro.tQuestionNum,
					wQuestionNum:this.autoPro.wQuestionNum,
					ctfNum: this.autoPro.ctfNum 
				})
		},
			getObj (dataList, count, score, type) {
				return {
					category: dataList.join(';'),
					count: count,
					score: score,
					type: type
				}
		},
		getArr (arr) {
				return [].concat(...arr.map(currentValue => Array.isArray(currentValue) ? this.getArr(currentValue) : currentValue))
		},
			// 二位数组对比总数据获取label
		childrenArr12 (name) {
			let arr = []
			this.typeOptions.forEach(item => {
				item.children.forEach(item2 => {
					this[name].forEach(item3 => {
						if (item3[0] == item.value) {
							if (item3[1] == item2.value) {
								arr.push([item.value,item2.value])
							}
						}
					})
				})
			})
			return arr
		},
		
			// 计算总分
			getTotalScoreNew (score) {
				this.totalScore = score.reduce((count, v) => count + v, 0)
				console.log('🚀 getTotalScore ~ this.totalScore', this.totalScore)
				this.$emit('on-change',this.copySelectQuestionList,this.totalScore,this.autoTotal,this.hasIllegalScore,{
					sQuestionNum:this.autoPro.sQuestionNum,
					mQuestionNum:this.autoPro.mQuestionNum,
					pQuestionNum:this.autoPro.pQuestionNum,
					tQuestionNum:this.autoPro.tQuestionNum,
					wQuestionNum:this.autoPro.wQuestionNum,
					ctfNum: this.autoPro.ctfNum 
				})
			},
			paperRandomsDetailNumber () {
				this.paperRandomsDetail.forEach(item => {
					switch (item.type) {
						case "ctf_no_env":
							this.autoPro.ctfNum = item.count
							this.autoPro.ctfScore = item.score
							if (item.category) {
								this.questionTypeCtfRef = item.category.split(';')
							}
							break;
						case "ctf_env":
							this.autoPro.ctfNumEnv = item.count
							this.autoPro.ctfScoreEnv = item.score
							if (item.category) {
								this.questionTypeCtfEnvRef = item.category.split(';')
							}
							break;
						case "qa":
							this.autoPro.wQuestionNum = item.count
							this.autoPro.wQuestionScore = item.score
							if (item.category) {
								this.questionWRef = item.category.split(';')
							}
							break;
						case "single_choice":
							this.autoPro.sQuestionNum = item.count
							this.autoPro.sQuestionScore = item.score
							if (item.category) {
								this.typeOptionsSingleRef = item.category.split(';')
							}
							break;
						case "multiple_choice":
							this.autoPro.mQuestionNum = item.count
							this.autoPro.mQuestionScore = item.score
							if (item.category) {
								this.typeOptionsMultipleRef = item.category.split(';')
							}
							break;
						case "judge":
							this.autoPro.pQuestionNum = item.count
							this.autoPro.pQuestionScore = item.score
							if (item.category) {
								this.typeOptionsJudgeRef = item.category.split(';')
							}
							break;
						case "blank_filling":
							this.autoPro.tQuestionNum = item.count
							this.autoPro.tQuestionScore = item.score
							if (item.category) {
								this.completionRef = item.category.split(';')
							}
							break;
					}
				})
			}

		}
	}
</script>
<style scoped>
.pageWrap {
  margin: 30px;
  background: #fff;
  height: calc(100vh - 111px);
  min-height: 620px;
  border-radius: 10px;
}

.pageHeader {
  padding: 20px 20px 0 20px;
}

.pageHeader .title {
  float: left;
  font-size: 18px;
}

.fixedHeightTable {
  margin: 20px 20px 0 20px;
}

.configClass {
  line-height: 32px;
  /*border: 1px solid #eee;*/
  border-top: none;
}
.configClass /deep/ .ivu-select .ivu-select-selection,
.configClass /deep/ .ivu-select-multiple .ivu-select-selection .ivu-select-placeholder{
	height:40px;
	line-height: 40px;
}
.configClass .ivu-btn-default {
  border-color: #999;
  color: #999;
}

ul {
  list-style: none;
}

.preQuestion h4,
.preQuestion p {
  word-break: break-all;
}

.more {
  width: 140px;
  height: 40px;
  line-height: 40px;
  color: #fff;
  text-align: center;
  background: #bbb;
  margin: 10px auto;
  cursor: pointer;
}

.questionList .ivu-tag {
  padding: 0 4px;
}

.questionList .ivu-divider-horizontal {
  margin: 12px 0;
}

.questionList .ivu-checkbox + span,
.ivu-checkbox-wrapper + span {
  margin-right: 0px;
}

#selQ .ivu-card-head .ivu-tag {
  margin: 0px;
}
.paper-automatic /deep/ .ivu-tooltip {
  padding: 0 5px;
}
</style>
<style>
/*.ivu-table-body{
        max-height :calc(100vh - 228px);
        overflow:hidden auto;
    }*/

#testPaper .fixedHeightTable .ivu-table-body {
  max-height: calc(100vh - 345px);
  overflow: hidden auto;
  overscroll-behavior: contain;
}

#allQ.ivu-card {
  border-radius: 10px 0 0 10px;
}

#selQ.ivu-card {
  border-radius: 0 10px 10px 0;
}

#allQ .ivu-card-head {
  /* background: #f5f8ff; */
  border-radius: 10px 0 0 0;
  height: 50px;
}

#selQ .ivu-card-head {
  /* background: #f5f8ff; */
  border-radius: 0 10px 0 0;
  height: 50px;
}

#allQ .ivu-card-body,
#selQ .ivu-card-body {
  height: calc(100vh - 380px);
  overflow-y: auto;
  word-break: break-all;
}

#selQ .ivu-card-body {
  border-radius: 0 0 0 10px;
}

#allQ .ivu-card-body {
  /*background: rgb(243, 246, 251);*/
  border-radius: 0 0 10px 0;
}

#selQ .ivu-tooltip-arrow {
  border-bottom-color: #bfbfbf;
}

#selQ .ivu-tooltip-inner {
  padding: 4px 6px;
  background-color: #bfbfbf;
  min-height: auto;
  cursor: pointer;
}

.up {
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: middle;
  background: url("../../../../assets/testPaper/up.png") no-repeat;
}

.up:hover {
  background: url("../../../../assets/testPaper/up_check.png") no-repeat;
}

.down {
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: middle;
  background: url("../../../../assets/testPaper/down.png") no-repeat;
}

.down:hover {
  background: url("../../../../assets/testPaper/down_check.png") no-repeat;
}

.remove {
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: middle;
  background: url("../../../../assets/testPaper/remove.png") no-repeat;
}

.remove:hover {
  background: url("../../../../assets/testPaper/remove_check.png") no-repeat;
}

.ivu-card-head .clear span {
  display: inline-block;
  width: 17px;
  height: 19px;
  margin-right: 5px;
  vertical-align: middle;
  background: url("../../../../assets/testPaper/clear.png") no-repeat;
}

.ivu-card-head .clear:hover {
  color: #2d8cf0;
}

.ivu-card-head .clear:hover span {
  background: url("../../../../assets/testPaper/clear_check.png") no-repeat;
}
</style>